package com.tanxiaoyao.wecon.widget;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.tanxiaoyao.wecon.R;
import com.tanxiaoyao.wecon.ui.ActivityMain;

/**
 * @author tanxiaoyao (junlidev@gmail.com)
 * @version 2014/8/31 20:24.
 */
public class PopMenu extends PopupWindow {
    private Context context;
    private View parent;

    private View child;

    public PopMenu(Context context, View parent, View child) {
        super(context);
        this.parent = parent;
        this.context = context;
        this.child = child;
        this.child.setFocusableInTouchMode(true);
//        设置属性
        setContentView(child);
        setWidth(ViewGroup.LayoutParams.FILL_PARENT);
        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        setFocusable(true);
        setBackgroundDrawable(new BitmapDrawable());
        setAnimationStyle(R.style.PopupAnimation);
        update();
    }

    public void show(int x, int y) {
        Log.i("xiaoyao", "内部状态" + this.isShowing());
        if ((this != null) && (!this.isShowing())) {
            Log.i("xiaoyao", "showAtLocation调用");
            this.showAtLocation(parent, Gravity.BOTTOM, x, y);
        } /*else if (this.isShowing()) {
            //正在显示则取消显示菜单
            this.dismiss();
            Log.i("xiaoyao", "dismiss调用");
        }*/
    }

}